import threading

num = 0
lock = threading.Lock


def run(n):
    global num
    for i in range(100000):
        lock.acquire()
        num += n  # num=num+n
        num -= n  # num=num-n
        lock.release()


if __name__ == '__main__':
    t1 = threading.Thread(target=run, name='线程1', args=(6,))
    t2 = threading.Thread(target=run, name='线程2', args=(9,))
    print(t1.name)
    print(t2.name)
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    print(num)
